const mongoose = require('mongoose')
const { Schema } = mongoose

const tagSchema = mongoose.Schema({
    title: {
        type: String,
        required: true,
    },
    author: {
        type: Schema.Types.ObjectId,
        ref: 'User',
    },
}, { versionKey: false, timestamps: true, })

tagSchema.methods.toJSONFor = function() {
    return {
        id: this._id,
        title: this.title,
        author: this.author
    }
}
const tagModel = mongoose.model('Tag', tagSchema);

module.exports = {
    tagModel
}